export const api = {

	baseURL() {
		// return 'http://wowzsf.tuanz.xhh.xinghuiblog.com/'
		return 'http://tuanz.wowzsf.xinzhic.com/'
	},

	user___login() {
		return this.baseURL() + 'user/login'
	},
	
	instance___fuben_list() {
		return this.baseURL() + 'instance/fuben_list'
	},
	
	group___auth_create_tuanben_group() {
		return this.baseURL() + 'group/auth_create_tuanben_group'
	},
	
	group___auth_info() {
		return this.baseURL() + 'group/auth_info'
	},
	
	group___auth_save_group_info() {
		return this.baseURL() + 'group/auth_save_group_info'
	},
	
	user___classes() {
		return this.baseURL() + 'user/classes'
	},
	
	group___auth_find_player() {
		return this.baseURL() + "group/auth_find_player"
	},
	
	group___auth_jieshan() {
		return this.baseURL() + "group/auth_jieshan"
	},
	
	group___auth_invite_player() {
		return this.baseURL() + 'group/auth_invite_player'
	},
	
	group___auth_group_char() {
		return this.baseURL() + 'group/auth_group_char'
	},
	
	group___auth_update_player_join_group() {
		return this.baseURL() + 'group/auth_update_player_join_group'
	},
	
	group___auth_update_player_leave_group() {
		return this.baseURL() + 'group/auth_update_player_leave_group'
	},
	
	software___version() {
		return this.baseURL() + 'software/version'
	},
	
	group___auth_ok_group() {
		return this.baseURL() + 'group/auth_ok_group'
	},
	
	upload___auth_jstoken() {
		return this.baseURL() + 'upload/auth_jstoken'
	},
	
	group___auth_report_player() {
		return this.baseURL() + 'group/auth_report_player'
	},
	
	group___auth_quequ_player_count() {
		return this.baseURL() + 'group/auth_quequ_player_count'
	},
	
	user___auth_tg_qrcode() {
		return this.baseURL() + 'user/auth_tg_qrcode'
	},
	
	user___auth_invite_list() {
		return this.baseURL() + 'user/auth_invite_list'
	},
	
	total___auth_kaituan_total() {
		return this.baseURL() + 'total/auth_kaituan_total'
	},
	
	total___auth_group_log() {
		return this.baseURL() + 'total/auth_group_log'
	},

	setToken(token) {
		uni.setStorageSync('token', token)
	},

	setCurrent(type, id) {
		const token = uni.getStorageSync('token')
		if (token && token != null && token.length > 0) {
			uni.setStorageSync('current' + token, {
				type: type,
				id: id
			})
		}
	},
	
	getCurrent() {
		const token = uni.getStorageSync('token')
		if (token && token != null && token.length > 0) {
			const curet = uni.getStorageSync('current' + token)
			if (curet) {
				return curet
			}
		}
		return null
	},
	
	removeCurrent() {
		const token = uni.getStorageSync('token')
		if (token && token != null && token.length > 0) {
			uni.removeStorageSync('current' + token)
		}
	},
  
	post(opt) {
		this.req(opt, 'POST')
	},

	get(opt) {
		this.req(opt, 'GET')
	},

	req(opt, method) {
		
		const token = uni.getStorageSync('token')
		
		let header = {
				'content-type': 'application/x-www-form-urlencoded'
			}
		if (opt.json) {
			header = {
					'content-type': 'application/json'
				}
			if (token && token != null && token.length > 0) {
				opt.url += '?token=' + token
			}
		} else {
			if (token && token != null && token.length > 0) {
				if (!opt.data) {
					opt.data = {
						token: token
					}
				} else {
					opt.data.token = token
				}
			}
		}

		uni.request({
			method: method,
			url: opt.url, 
			header: header,
			data: opt.data,
			success: (res) => {
				if (res.data.code == 1) {
					if (opt.success) {
						opt.success(res.data)
					}
				} else if (res.data.code == 403) {
					
					
					
				} else {
					if (opt.fail) {
						opt.fail(res.data.code_str, res.data)
					}
				}
			}, 
			fail: (error) => {
				if (opt.fail) {
					opt.fail('网络异常')
				}
			}
		})
	}
}